package com.hkzhao.reportingsystem.component;

import com.hkzhao.reportingsystem.dto.QueueEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//审核陈坤发送邮件通知队列
@Component
public class VerifySuccessSender {
    private static Logger LOOGER = LoggerFactory.getLogger(VerifySuccessSender.class);
    @Autowired
    private AmqpTemplate amqpTemplate;
    public void sendMessage(String username,Long delayTimes)
    {
        //给审核陈坤延迟队列发消息
        amqpTemplate.convertAndSend(QueueEnum.QUEUE_REGISTER_SUCCESS_TTL.getExchange(), QueueEnum.QUEUE_REGISTER_SUCCESS_TTL.getRouteKey(), username, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                //给消息设置延迟毫秒值
                message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
                return message;
            }
        });
        LOOGER.info("发送审核陈坤实际消息队列:{}",username);
    }
}
